package com.axon.components.controls
{
	import com.axon.base.helpers.AxUtils;
	import com.axon.components.containers.AxPanel;
	import com.axon.components.containers.AxTitleWindowSizeable;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	
	import mx.controls.DateField;
	import mx.core.Container;

	public class AxDateField extends DateField
	{
		public function AxDateField()
		{
			super();
			formatString = AxUtils.shortDateFormat();
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
    	override protected function keyDownHandler(event: KeyboardEvent):void
    	{
			var theParent: DisplayObjectContainer = parent;

    		switch (event.charCode) {
    			
    			case Keyboard.ENTER:
				
					while ((theParent != null) && !(theParent is AxPanel) && !(theParent is AxTitleWindowSizeable))
						theParent = theParent.parent;
						
					if ( (theParent != null)&& (Container(theParent).defaultButton) )
						Container(theParent).defaultButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK))
					
					break;
				
				case Keyboard.ESCAPE:
				
					while ((theParent != null) && !(theParent is AxPanel) && !(theParent is AxTitleWindowSizeable))
						theParent = theParent.parent;
						
					if (theParent != null) 
						theParent.dispatchEvent(event.clone());
						
					break;
					
    			case Keyboard.SPACE:
    						
					selectedDate = AxUtils.currentDate();
					break;
					
//				case Keyboard.UP:
//				
//					if (selectedDate)
//						selectedDate += 1;
//					
//				case Keyboard.DOWN:
//				
//					if (selectedDate)
//						selectedDate -= 1;
					
				default:
				
					super.keyDownHandler(event);
				
    		}
    	}

	}
}